package com.easychat.controller.Admin;

import com.easychat.annotation.GlobalInterceptor;
import com.easychat.controller.ABaseController;
import com.easychat.entity.enums.*;
import com.easychat.entity.po.UserInfo;
import com.easychat.entity.query.UserInfoQuery;
import com.easychat.entity.vo.PaginationResultVO;
import com.easychat.entity.vo.ResponseVO;
import com.easychat.service.UserInfoBeautyService;
import com.easychat.service.UserInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @Author Dongdong
 * @注释 用户联系人
 */
@RestController("adminUserInfoController")
@RequestMapping("/admin")
public class AdminUserInfoController extends ABaseController {

    @Resource
    private UserInfoBeautyService userInfoBeautyService;
    @Resource
    private UserInfoService userInfoService;



    @RequestMapping("/loadUser")
    @GlobalInterceptor
    public ResponseVO search(UserInfoQuery userInfoQuery) {
        userInfoQuery.setOrderBy("create_time desc");
        PaginationResultVO<UserInfo> resultVo = userInfoService.findListByPage(userInfoQuery);

        return getSuccessResponseVO(resultVo);
    }

    @RequestMapping("/updateUserStatus")
    @GlobalInterceptor
    public ResponseVO updateUserStatus(@NotEmpty String userId, @NotNull Integer status) {
        UserStatusEnum statusEnum =  UserStatusEnum.getByCode(status);
        UserInfo userInfo = new UserInfo();
        userInfo.setStatus(statusEnum.getStatus());
        userInfoService.updateUserStatus(status, userId);
        return getSuccessResponseVO(userInfo);
    }

    @RequestMapping("/forceOffLine")
    @GlobalInterceptor
    public ResponseVO forceOffline(@NotEmpty String userId) {
       userInfoService.forceOffline(userId);
        return getSuccessResponseVO(null);
    }






}
